home *** CD-ROM | disk | FTP | other *** search
/ Danny Amor's Online Library / Danny Amor's Online Library - Volume 1.iso / html / faqs / faq / lisp-faq / part1 next >
Encoding:
Text File  |  1995-07-25  |  75.2 KB  |  1,578 lines

  1. Subject: FAQ: Lisp Frequently Asked Questions 1/7 [Monthly posting]
  2. Newsgroups: comp.lang.lisp,news.answers,comp.answers
  3. From: mkant+@cs.cmu.edu (Mark Kantrowitz)
  4. Date: 13 Nov 1994 08:00:44 GMT
  5.  
  6. Archive-name: lisp-faq/part1
  7. Last-Modified: Fri Nov 11 17:20:12 1994 by Mark Kantrowitz
  8. Version: 1.51
  9. Maintainer: Mark Kantrowitz and Barry Margolin <ai+lisp-faq@cs.cmu.edu>
  10. URL: http://www.cs.cmu.edu:8001/Web/Groups/AI/html/faqs/lang/lisp/top.html
  11. Size: 77094 bytes, 1579 lines
  12.  
  13. ;;; ****************************************************************
  14. ;;; Answers to Frequently Asked Questions about Lisp ***************
  15. ;;; ****************************************************************
  16. ;;; Written by Mark Kantrowitz and Barry Margolin
  17. ;;; lisp_1.faq 
  18.  
  19. This post contains Part 1 of the Lisp FAQ.
  20.  
  21. If you think of questions that are appropriate for this FAQ, or would
  22. like to improve an answer, please send email to us at ai+lisp-faq@cs.cmu.edu.
  23.  
  24. Note that the lisp-faq mailing list is for discussion of the content
  25. of the FAQ posting only.  It is not the place to ask questions about Lisp;
  26. use either the common-lisp@ai.sri.com mailing list or the
  27. comp.lang.lisp newsgroup for that.  If a question appears frequently
  28. in one of those forums, it will get added to the FAQ list.
  29.  
  30. *** Copyright:
  31.  
  32. Copyright (c) 1992-94 by Mark Kantrowitz and Barry Margolin. 
  33. All rights reserved. 
  34.  
  35. This FAQ may be freely redistributed in its entirety without
  36. modification provided that this copyright notice is not removed.  It
  37. may not be sold for profit or incorporated in commercial documents
  38. (e.g., published for sale on CD-ROM, floppy disks, books, magazines,
  39. or other print form) without the prior written permission of the
  40. copyright holder.  Permission is expressly granted for this document
  41. to be made available for file transfer from installations offering
  42. unrestricted anonymous file transfer on the Internet.
  43.  
  44. If this FAQ is reproduced in offline media (e.g., CD-ROM, print form,
  45. etc.), a complimentary copy should be sent to Mark Kantrowitz, School
  46. of Computer Science, Carnegie Mellon University, 5000 Forbes Avenue,
  47. Pittsburgh, PA 15213-3891 USA.
  48.  
  49. This article is provided AS IS without any express or implied warranty.
  50.  
  51. *** Topics Covered:
  52.  
  53. There are currently seven parts to the Lisp FAQ:
  54.  
  55.    1. Introductory Matter and Bibliography of Introductions and References
  56.    2. General Questions
  57.    3. Common Programming Pitfalls
  58.    4. Lisp Implementations and Mailing Lists
  59.    5. Object-oriented Programming in Lisp
  60.    6. FTP Archives and Resources
  61.    7. Lisp Window Systems and GUIs
  62.  
  63. All parts are posted to comp.lang.lisp. Part 5 is cross-posted to the
  64. comp.lang.clos newsgroup.  
  65.  
  66. Topics Covered (Part 1):
  67.  
  68.   [1-0]   What is the purpose of this newsgroup?
  69.   [1-1]   What is the difference between Scheme and Common Lisp?
  70.   [1-2]   Lisp books, introductions, documentation, periodicals,
  71.           journals, and conference proceedings. 
  72.   [1-3]   How can I improve my Lisp programming style and coding efficiency?
  73.   [1-4]   Where can I learn about implementing Lisp interpreters and compilers?
  74.   [1-5]   What is the "minimal" set of primitives needed for a Lisp
  75.           interpreter? 
  76.   [1-6]   What does CLOS, PCL, X3J13, CAR, CDR, ... mean? 
  77.   [1-7]   Lisp Job Postings
  78.  
  79. Topics Covered (Part 2):
  80.  
  81.   [2-1]   Is there a GNU-Emacs interface to Lisp?
  82.   [2-2]   When should I use a hash table instead of an association list?
  83.   [2-3]   What is the equivalent of EXPLODE and IMPLODE in Common Lisp?
  84.   [2-4]   Is Lisp inherently slower than more conventional languages such as C?
  85.   [2-5]   Why does Common Lisp have "#'"?
  86.   [2-6]   How do I call non-Lisp functions from Lisp?
  87.   [2-7]   Can I call Lisp functions from other languages?
  88.   [2-8]   I want to call a function in a package that might not exist at
  89.           compile time. How do I do this?  
  90.   [2-9]   What is CDR-coding?
  91.   [2-10]  What is garbage collection?
  92.   [2-11]  How do I save an executable image of my loaded Lisp system?
  93.           How do I run a Unix command in my Lisp? How do I exit Lisp?
  94.   [2-12]  I'm porting some code from a Symbolics Lisp machine to some
  95.           other platform, and there are strange characters in the code.
  96.           What do they mean?  
  97.   [2-13]  History: Where did Lisp come from?
  98.   [2-14]  How do I find the argument list of a function?
  99.           How do I get the function name from a function object?
  100.   [2-15]  How can I have two Lisp processes communicate via unix sockets?
  101.   [2-16]  How can I create a stream that acts like UNIX's /dev/null
  102.           (i.e., gobbles any output and immediately signals EOF on
  103.           input operations)?
  104.   [2-17]  Read-time conditionalization of code (#+ #- and *features*)
  105.   [2-18]  What reader macro characters are used in major Lisp systems?
  106.   [2-19]  How do I determine if a file is a directory or not? 
  107.           How do I get the current directory name from within a Lisp 
  108.           program? Is there any way to create a directory?
  109.   [2-20]  What is a "Lisp Machine" (LISPM)?
  110.   [2-21]  How do I tell if a symbol names a function and not a macro?
  111.  
  112. Common Pitfalls (Part 3):
  113.  
  114.   [3-0]  Why does (READ-FROM-STRING "foobar" :START 3) return FOOBAR
  115.          instead of BAR?  
  116.   [3-1]  Why can't it deduce from (READ-FROM-STRING "foobar" :START 3)
  117.          that the intent is to specify the START keyword parameter
  118.          rather than the EOF-ERROR-P and EOF-VALUE optional parameters?   
  119.   [3-2]  Why can't I apply #'AND and #'OR?
  120.   [3-3]  I used a destructive function (e.g. DELETE, SORT), but it
  121.          didn't seem to work.  Why? 
  122.   [3-4]  After I NREVERSE a list, it's only one element long.  After I
  123.          SORT a list, it's missing things.  What happened? 
  124.   [3-5]  Why does (READ-LINE) return "" immediately instead of waiting
  125.          for me to type a line?  
  126.   [3-6]  I typed a form to the read-eval-print loop, but nothing happened. Why?
  127.   [3-7]  DEFMACRO doesn't seem to work.
  128.          When I compile my file, LISP warns me that my macros are undefined
  129.          functions, or complains "Attempt to call <function> which is 
  130.          defined as a macro.
  131.   [3-8]  Name conflict errors are driving me crazy! (EXPORT, packages)
  132.   [3-9]  Closures don't seem to work properly when referring to the
  133.          iteration variable in DOLIST, DOTIMES, DO and LOOP.
  134.   [3-10] What is the difference between FUNCALL and APPLY?
  135.   [3-11] Miscellaneous things to consider when debugging code.
  136.   [3-12] When is it right to use EVAL?
  137.   [3-13] Why does my program's behavior change each time I use it?
  138.   [3-14] When producing formatted output in Lisp, where should you put the
  139.          newlines (e.g., before or after the line, FRESH-LINE vs TERPRI,
  140.          ~& vs ~% in FORMAT)?
  141.   [3-15] I'm using DO to do some iteration, but it doesn't terminate. 
  142.   [3-16] My program works when interpreted but not when compiled!
  143.  
  144. Lisp Implementations and Mailing Lists (Part 4):
  145.  
  146.   [4-0]   Free Common Lisp implementations.
  147.   [4-1]   Commercial Common Lisp implementations.
  148.   [4-1a]  Lisp-to-C translators
  149.   [4-2]   Scheme Implementations
  150.   [4-4]   Free Implementations of Other Lisp Dialects
  151.   [4-5]   Commercial Implementations of Other Lisp Dialects
  152.   [4-6]   What is Dylan?
  153.   [4-7]   What is Pearl Common Lisp?
  154.   [4-9]   What Lisp-related discussion groups and mailing lists exist?
  155.   [4-10]  ANSI Common Lisp -- Where can I get a copy of the draft standard?
  156.  
  157. Object-oriented Programming in Lisp (Part 5):
  158.  
  159.   [5-0]   What is CLOS (PCL) and where can I get it?
  160.           How do you pronounce CLOS? What is the Meta-Object Protocol (MOP)?
  161.   [5-1]   What documentation is available about object-oriented
  162.           programming in Lisp?  
  163.   [5-2]   How do I write a function that can access defstruct slots by
  164.           name?  I would like to write something like 
  165.           (STRUCTURE-SLOT <object> '<slot-name>).   
  166.   [5-3]   How can I list all the CLOS instances in a class?
  167.   [5-4]   How can I store data and CLOS instances (with possibly circular
  168.           references) on disk so that they may be retrieved at some later
  169.           time? (Persistent Object Storage)
  170.   [5-5]   Given the name of a class, how can I get the names of its slots?
  171.   [5-6]   Free CLOS software.
  172.   [5-7]   Common CLOS Blunders
  173.  
  174. FTP Resources (Part 6):
  175.  
  176.   [6-0] General information about FTP Resources for Lisp
  177.   [6-1] Repositories of Lisp Software
  178.   [6-3] Publicly Redistributable Lisp Software
  179.   [6-6] Formatting code in LaTeX (WEB and other literate programming tools)
  180.   [6-7] Where can I get an implementation of Prolog in Lisp?
  181.   [6-8] World-Wide Web (WWW) Resources
  182.  
  183. Lisp Window Systems and GUIs (Part 7):
  184.   [7-1] How can I use the X Window System or other GUIs from Lisp?
  185.   [7-2] What Graphers/Browsers are available?
  186.  
  187. Search for \[#\] to get to question number # quickly.
  188.  
  189. *** Recent Changes:
  190.  
  191. ;;; 1.48:
  192. ;;; 13-JUL-94 mk    Updated Marlais entry in part 4.
  193. ;;; 14-JUL-94 mk    Updated DTP entry in part 6.
  194. ;;; 14-JUL-94 mk    Added entry on Lisp2Wish to part 7.
  195. ;;; 15-JUL-94 mk    Updated WCL entry (version 2.2 for solaris).
  196. ;;; 21-JUL-94 mk    Expanded ILU entry in part 6.
  197. ;;; 22-JUL-94 mk    Updated the Common Lisp Repository entry with information
  198. ;;;                 about the Prime Time Freeware for AI CD-ROM publication,
  199. ;;;                 keyword searching, etc., etc., etc.
  200. ;;; 11-AUG-94 mk    Added ftp site for source code to Graham's "On Lisp" book.
  201. ;;; 12-AUG-94 mk    Lisp-Jobs mailing list has moved.
  202. ;;; 12-AUG-94 mk    Added amiga-lisp mailing list to [4-9].
  203. ;;;
  204. ;;; 1.49:
  205. ;;; 23-AUG-94 mk    Moved the lisp-faq mailing list (for maintenance of the
  206. ;;;                 FAQ) from think.com to ai+lisp-faq@cs.cmu.edu.
  207. ;;;                 FAQ no longer available from ftp.think.com.
  208. ;;; 23-AUG-94 mk    Digital Press is now owned by Butterworth-Heinemann,
  209. ;;;                 and their new address is: 
  210. ;;;                    Digital Press, 80 Montvale Avenue, Stoneham, MA 02180
  211. ;;;                    Tel: 800-366-2665 (617-438-8464), Fax: 617-297-4851.
  212. ;;; 26-AUG-94 mk    Updated ILISP entry in [2-1].
  213. ;;; 26-AUG-94 mk    Added entry on JLISP to [4-4].
  214. ;;; 29-AUG-94 mk    CLtL2 now available by anonymous FTP, courtesy of
  215. ;;;                 Butterworth-Heinemann, the new owners of Digital Press.
  216. ;;; 30-AUG-94 mk    Numbers for Digital Press have changed. They are now      
  217. ;;;                 Tel: 800-366-2665 (USA) or 617-928-2500
  218. ;;;                 Fax: 800-446-6520 (USA) or 617-933-6333
  219. ;;;  8-SEP-94 mk    Corrected expansion for SC22/WG16 in [1-6] glossary.
  220. ;;;
  221. ;;; 1.50:
  222. ;;; 14-SEP-94 mk    Improved IDEAL entry in [6-3].
  223. ;;; 20-SEP-94 mk    Added "How do I exit Lisp?" to [2-11].
  224. ;;; 22-SEP-94 mk    Added Paul Graham's implementation of Prolog in Common Lisp
  225. ;;;                 to [6-7].
  226. ;;; 11-OCT-94 mk    Updated Venue entry in Part 4, and slight revisions in most
  227. ;;;                 other commercial Lisp implementations.
  228. ;;; 12-OCT-94 mk    Updated Harlequin Lispworks entry, and added new entry on
  229. ;;;                 Harlequin FreeLisp to part 4.
  230. ;;; 12-OCT-94 mk    Added ftp site for Kamin's original pascal implementation
  231. ;;;                 of his interpreters to [1-4].
  232. ;;;
  233. ;;; 1.51:
  234. ;;; 13-OCT-94 mk    Added   [2-21]  How do I tell if a symbol names a function
  235. ;;;                 and not a macro?
  236. ;;; 20-OCT-94 mk    Added [5-7] Common CLOS Blunders by Marty Hall.
  237. ;;;  3-NOV-94 mk    Added Christian Queinnec's Lisp book to [1-4].
  238. ;;;  4-NOV-94 mk    Updated CMU CL entry. 17f w/ Solaris, SGI MIPS, and DEC
  239. ;;;                 Alpha released.
  240. ;;; 10-NOV-94 mk    Digitool to produce PowerPC version of MCL.
  241. ;;; 11-NOV-94 mk    Updated ISO Lisp paragraph in [4-10].
  242. ;;; 11-NOV-94 mk    Updated LispWorks for Harlequin entry in part 4.
  243.  
  244. *** Introduction:
  245.  
  246. Certain questions and topics come up frequently in the various network
  247. discussion groups devoted to and related to Lisp.  This file/article is
  248. an attempt to gather these questions and their answers into a convenient
  249. reference for Lisp programmers.  It (or a reference to it) is posted
  250. periodically.  The hope is that this will cut down on the user time and
  251. network bandwidth used to post, read and respond to the same questions
  252. over and over, as well as providing education by answering questions
  253. some readers may not even have thought to ask.
  254.  
  255. This is not a Lisp tutorial, nor is it an exhaustive list of all Lisp
  256. intricacies.  Lisp is a very powerful and expressive language, but with
  257. that power comes many complexities.  This list attempts to address the
  258. ones that average Lisp programmers are likely to encounter.  If you are
  259. new to Lisp, see the answer to the question "How can I learn Lisp?".
  260.  
  261. The latest version of this FAQ is available via anonymous FTP from CMU:
  262.  
  263.    To obtain the files from CMU, connect by anonymous FTP to 
  264.       ftp.cs.cmu.edu:/user/ai/pubs/faqs/lisp/  [128.2.206.173]
  265.    using username "anonymous" and password "name@host" (substitute your
  266.    email address) or via AFS in the Andrew File System directory
  267.       /afs/cs.cmu.edu/project/ai-repository/ai/pubs/faqs/lisp/
  268.    and get the files lisp_1.faq, lisp_2.faq, lisp_3.faq, lisp_4.faq,
  269.    lisp_5.faq, lisp_6.faq and lisp_7.faq.
  270.  
  271. You can also obtain a copy of the FAQ by sending a message to
  272. ai+query@cs.cmu.edu with 
  273.    Send Lisp FAQ
  274. in the message body.
  275.  
  276. The FAQ postings are also archived in the periodic posting archive on
  277.    rtfm.mit.edu:/pub/usenet/news.answers/lisp-faq/ [18.181.0.24]
  278. If you do not have anonymous ftp access, you can access the archive by
  279. mail server as well.  Send an E-mail message to
  280. mail-server@rtfm.mit.edu with "help" and "index" in the body on
  281. separate lines for more information.
  282.  
  283. An automatically generated HTML version of the Lisp FAQ is accessible by
  284. WWW as part of the AI-related FAQs Mosaic page. The URL for this
  285. resource is
  286.    http://www.cs.cmu.edu:8001/Web/Groups/AI/html/faqs/top.html
  287. The direct URL for the Lisp FAQ is
  288.    http://www.cs.cmu.edu:8001/Web/Groups/AI/html/faqs/lang/lisp/top.html
  289.  
  290. Unless otherwise specified, the Lisp dialect referred to is Common Lisp,
  291. as defined by "Common Lisp: the Language" (aka "CLtL1") as well as
  292. corrections (but not enhancements) from "Common Lisp: the Language, 2nd
  293. Edition" (aka "CLtL2"), both by Guy L. Steele, Jr. and published by
  294. Digital Press. Note that CLtL2 is NOT an official specification for
  295. the language; ANSI Committee X3J13 is preparing such a specification.
  296. See question [4-10] for information on the status of the ANSI
  297. specification for Common Lisp. Enhancements such as CLOS, conditions,
  298. and the LOOP macro will be referred to separately.
  299.  
  300. If you need to cite the FAQ for some reason, use the following format:
  301.    Mark Kantrowitz and Barry Margolin, "Answers to Frequently Asked
  302.    Questions about Lisp", comp.lang.lisp, <month>, <year>,
  303.    ftp.cs.cmu.edu:/user/ai/pubs/faqs/lisp/lisp_?.faq, ai+lisp-faq@cs.cmu.edu.
  304.  
  305. ----------------------------------------------------------------
  306. Subject: [1-0] What is the purpose of this newsgroup?
  307.  
  308. The newsgroup comp.lang.lisp exists for general discussion of
  309. topics related to the programming language Lisp. For example, possible
  310. topics can include (but are not necessarily limited to):
  311.    announcements of Lisp books and products
  312.    discussion of programs and utilities written in Lisp
  313.    discussion of portability issues
  314.    questions about possible bugs in Lisp implementations
  315.    problems porting an implementation to some architecture
  316. Postings should be of general interest to the Lisp community. See also
  317. question [4-9]. Postings asking for solutions to homework problems are
  318. inappropriate. 
  319.  
  320. Every so often, somebody posts an inflammatory message, such as
  321.    My programming language is better than yours (Lisp vs. C/Prolog/Scheme). 
  322.    Loop (or Series) should/shouldn't be part of the language.
  323. These "religious" issues serve no real purpose other than to waste
  324. bandwidth. If you feel the urge to respond to such a post, please do
  325. so through a private e-mail message. 
  326.  
  327. Questions about object oriented programming in Lisp should be directed
  328. to the newsgroup comp.lang.clos. Similarly, questions about the
  329. programming language Scheme should be directed to the newsgroup
  330. comp.lang.scheme. Discussion of functional programming language issues
  331. should be directed to the newsgroup comp.lang.functional. Discussion
  332. of AI programs implemented in Lisp should sometimes be cross-posted to
  333. the newsgroup comp.ai.
  334.  
  335. ----------------------------------------------------------------
  336. Subject: [1-1] What is the difference between Scheme and Common Lisp?
  337.  
  338. Scheme is a dialect of Lisp that stresses conceptual elegance and
  339. simplicity. It is specified in R4RS and IEEE standard P1178. (See
  340. the Scheme FAQ for details on standards for Scheme.) Scheme is much
  341. smaller than Common Lisp; the specification is about 50 pages,
  342. compared to Common Lisp's 1300 page draft standard. (See question
  343. [4-10] for details on standards for Common Lisp.) Advocates of Scheme
  344. often find it amusing that the Scheme standard is shorter than the
  345. index to CLtL2. 
  346.  
  347. Scheme is often used in computer science curricula and programming
  348. language research, due to its ability to represent many programming
  349. abstractions with its simple primitives. Common Lisp is often used for
  350. real world programming because of its large library of utility
  351. functions, a standard object-oriented programming facility (CLOS), and
  352. a sophisticated condition handling system.
  353.  
  354. See the Scheme FAQ for information about object-oriented programming
  355. in Scheme. 
  356.  
  357. In Common Lisp, a simple program would look something like the
  358. following:
  359.  
  360.    (defun fact (n)
  361.      (if (< n 2)
  362.          1
  363.          (* n (fact (1- n)))))
  364.  
  365. In Scheme, the equivalent program would like like this:
  366.  
  367.    (define fact
  368.      (lambda (n)
  369.        (if (< n 2)
  370.            1
  371.          (* n (fact (- n 1))))))
  372.  
  373. Experienced Lisp programmers might write this program as follows in order
  374. to allow it to run in constant space:
  375.  
  376.    (defun fact (n)
  377.      (labels ((tail-recursive-fact (counter accumulator)
  378.                 (if (> counter n)
  379.                     accumulator
  380.                     (tail-recursive-fact (1+ counter)
  381.                                          (* counter accumulator)))))
  382.        (tail-recursive-fact 1 1)))
  383.  
  384. Whereas in Scheme the same computation could be written as follows:
  385.  
  386.    (define fact
  387.      (lambda (n)
  388.        (letrec ((tail-recursive-fact
  389.                  (lambda (counter accumulator)
  390.                    (if (> counter n)
  391.                        accumulator
  392.                      (tail-recursive-fact (+ counter 1)
  393.                                           (* counter accumulator))))))
  394.                (tail-recursive-fact 1 1))))
  395.  
  396. or perhaps (using IEEE named LETs):
  397.  
  398.    (define fact
  399.      (lambda (n)
  400.        (let loop ((counter n)
  401.                   (accumulator 1))
  402.             (if (< counter 2)
  403.                 accumulator
  404.               (loop (- counter 1)
  405.                     (* accumulator counter))))))
  406.  
  407. Some Schemes allow one to use the syntax (define (fact n) ...) instead
  408. of (define fact (lambda (n) ...)).
  409.  
  410. ----------------------------------------------------------------
  411. Subject: [1-2] Lisp books, introductions, documentation, periodicals,
  412.                journals, and conference proceedings. 
  413.  
  414. There are several good Lisp introductions and tutorials:
  415.  
  416.    1. David S. Touretzky
  417.       "Common Lisp: A Gentle Introduction to Symbolic Computation"
  418.       Benjamin/Cummings Publishers, Redwood City, CA, 1990. 592 pages.
  419.       ISBN 0-8053-0492-4. 
  420.            Perhaps the best tutorial introduction to the language. It has
  421.            clear and correct explanations, and covers some fairly advanced
  422.            topics. The book is an updated Common Lisp version of the 1984
  423.            edition published by Harper and Row Publishers. 
  424.  
  425.            Three free Lisp educational tools which were used in the book --
  426.            Evaltrace, DTRACE and SDRAW -- are available by anonymous ftp from
  427.               b.gp.cs.cmu.edu:/usr/dst/public/lisp/
  428.               b.gp.cs.cmu.edu:/usr/dst/public/evaltrace/
  429.        Evaltrace is a graphical notation for explaining how evaluation
  430.        works and is described in "Visualizing Evaluation in
  431.        Applicative Languages" by David S. Touretzky and Peter Lee,
  432.        CACM 45-59, October 1992. DTRACE is a "detailed trace" which
  433.        provides more information than the tracing tools provided with
  434.        most Common Lisp implementations. SDRAW is a read-eval-draw
  435.        loop that evaluates Lisp expressions and draws the result as a
  436.        cons cell diagram (for both X11 and ascii terminals). Also
  437.        available is PPMX, a tool for pretty printing macro expansions.
  438.  
  439.    2. Robert Wilensky
  440.       "Common LISPcraft"
  441.       W. W. Norton, 1986. 500 pages. ISBN 0-393-95544-3.
  442.  
  443.    3. Wade L. Hennessey 
  444.       "Common Lisp"
  445.       McGraw-Hill, 1989. 395 pages.
  446.            Fairly good, but jumps back and forth from the simple to the
  447.            complex rather quickly, with no clear progression in difficulty.
  448.  
  449.    4. Laurent Siklossy
  450.       "Let's Talk LISP"
  451.       Prentice-Hall, NJ, 1976. 237 pages.
  452.            Good introduction, but quite out of date.
  453.  
  454.    5. Stuart C. Shapiro
  455.       "Common Lisp: An Interactive Approach"
  456.       Computer Science Press/W.H. Freeman, New York, 1992.
  457.       ISBN 0-7167-8218-9
  458.          The errata for the book may be obtained by anonymous ftp from
  459.          ftp.cs.buffalo.edu:/users/shapiro/clerrata.ps
  460.  
  461. Other introductions to Lisp include:
  462.  
  463.    1. A. A. Berk.
  464.       "LISP, The Language of Artificial Intelligence"
  465.       Van Nostrand Reinhold, 1985. 160 pages.
  466.  
  467.    2. Paul Y. Gloess.
  468.       "An Alfred handy guide to Understanding LISP"
  469.       Alfred Publishers (Sherman Oaks, CA), 1982. 64 pages.
  470.  
  471.    3. Ward D. Maurer.
  472.       "The Programmer's Introduction to LISP"
  473.       American Elsevier, 1972. 112 pages.
  474.  
  475.    4. Hank Bromley and Richard Lamson.
  476.       "LISP Lore: A Guide to Programming the LISP Machine"
  477.       Kluwer Academic (Boston), 1987. 337 pages.
  478.  
  479.    5. Sharam Hekmatpour.
  480.       "Introduction to LISP and Symbol Manipulation"
  481.       Prentice Hall (New York), 1988. 303 pages.
  482.  
  483.    6. Deborah G. Tatar
  484.       "A programmer's guide to Common Lisp"
  485.       Digital Press, 1987. 327 pages. ISBN 0-932376-87-8.
  486.            Good introduction on Common Lisp for programmers familiar
  487.            with other programming languages, such as FORTRAN, PASCAL, or C.
  488.  
  489.    7. Timothy Koschmann
  490.       "The Common Lisp Companion"
  491.       John Wiley & Sons, 1990. ISBN 0-471-503-8-8.
  492.            Targeted for those with some programming experience who wish to 
  493.            learn draft-ANSI Common Lisp, including CLOS and the CL condition 
  494.            system. Examples progress incrementally from simple numerical 
  495.            calculation all the way to a logic-programming extension to CL.
  496.   
  497. More advanced introductions to Lisp and its use in Artificial
  498. Intelligence include:
  499.  
  500.    1. Peter Norvig.
  501.       "Paradigms of AI Programming: Case Studies in Common Lisp"
  502.       Morgan Kaufmann, 1992. 946 pages. ISBN 1-55860-191-0. $49.95.
  503.  
  504.         Provides an in-depth exposition of advanced AI programming techniques
  505.         and includes large-scale detailed examples. The book is the most
  506.         advanced AI/Common-Lisp programming text and reference currently
  507.         available, and hence is not for the complete novice.  It focuses on the
  508.         programming techniques necessary for building large AI systems,
  509.         including object-oriented programming, and has a strong performance
  510.         orientation.
  511.  
  512.         The text is marked by its use of "non-toy" examples to illustrate the
  513.         techniques. All of the examples are written in Common Lisp, and copies
  514.         of the source code are available by anonymous ftp from
  515.         unix.sri.com:/pub/norvig and on disk in Macintosh or DOS format from
  516.         the publisher. Some of the techniques described include rule-based
  517.         pattern matching (GPS, Eliza, a subset of Macsyma, the Emycin expert
  518.         system shell), constraint propagation and backtracking (Waltz
  519.         line-labelling), alpha-beta search (Othello), natural language
  520.         processing (top-down, bottom-up and chart parsing), logic-programming
  521.         (unification and Prolog), interpreters and compilers for Scheme, and
  522.         object-oriented programming (CLOS).
  523.  
  524.         The examples are also used to illustrate good programming style and
  525.         efficiency. There is a guide to trouble-shooting and debugging Lisp
  526.         programs, a style guide, and a discussion of portability problems.
  527.         Some of the efficiency techniques described include memoization,
  528.         data indexing, compilation, delaying computation, proper use of
  529.         declarations, avoiding garbage collection, and choosing and using the
  530.         correct data structure.
  531.  
  532.         The book also serves as an advanced introduction to Common Lisp, with
  533.         sections on the Loop macro, CLOS and sequences, and some coverage of 
  534.         error handling, series, and the package facility.
  535.  
  536.    2. Eugene Charniak, Christopher K. Riesbeck, Drew V. McDermott
  537.       and James R. Meehan.
  538.       "Artificial Intelligence Programming", 2nd edition.
  539.       Lawrence Erlbaum Associates (Hillsdale, NJ), 1987. 533 pages.
  540.            Provides many nice code fragments, all of which are written
  541.            in Common Lisp. The first half of the book covers topics
  542.            like macros, the reader, data structures, control structures,
  543.            and defstructs. The second half of the book describes
  544.            programming techniques specific to AI, such as
  545.            discrimination nets, production systems, deductive database
  546.            retrieval, logic programming, and truth maintenance.
  547.  
  548.    3. Patrick H. Winston and Berthold K. P. Horn.
  549.       "LISP", 3rd edition.
  550.       Addison-Wesley (Reading, MA), 1989. 611 pages. ISBN 0-201-08319-1
  551.            Covers the basic concepts of the language, but also gives a lot
  552.            of detail about programming AI topics such as rule-based expert
  553.            systems, forward chaining, interpreting transition trees, 
  554.            compiling transition trees, object oriented programming,
  555.            and finding patterns in images. Not a tutorial. Has many
  556.            good examples. Source code for the examples is available by
  557.            anonymous ftp from ftp.ai.mit.edu:/pub/lisp3/. (The code runs in
  558.            Lucid, Allegro, KCL, GCLisp, MCL, Symbolics Genera. Send mail
  559.            with subject line "help" to ai3@ai.mit.edu for more information.)
  560.  
  561.    4. John R. Anderson, Albert T. Corbett, and Brian J. Reiser.
  562.       "Essential LISP"
  563.       Addison-Wesley (Reading, MA), 1987. 352 pages.
  564.            Concentrates on how to use Lisp with iteration and recursion.
  565.  
  566.    5. Robert D. Cameron and Anthony H. Dixon
  567.       "Symbolic Computing with Lisp"
  568.       Prentice-Hall, 1992, 326 pages. ISBN 0-13-877846-9.
  569.            The book is intended primarily as a third-year computer science
  570.            text. In terms of programming techniques, it emphasizes recursion
  571.            and induction, data abstraction, grammar-based definition of Lisp
  572.            data structures and functional programming style. It uses
  573.            two Lisp languages: 
  574.                 (1) a purely functional subset of Lisp called Small Lisp and
  575.                 (2) Common Lisp.
  576.            An MS-DOS interpreter for Small Lisp (including source) is
  577.            provided with the book.  It considers applications of Lisp
  578.            to formal symbolic data domains: algebraic expressions,
  579.            logical formulas, grammars and programming languages. 
  580.  
  581.    6. Hasemer and Domingue.
  582.       "Common Lisp Programming for Artificial Intelligence"
  583.       Addison-Wesley, 1989.
  584.  
  585.    7. Steven Tanimoto
  586.       "The Elements of Artificial Intelligence: An Introduction Using Lisp"
  587.       Computer Science Press, Rockville, MD, 1987, 530 pages.
  588.  
  589.    8. Patrick R. Harrison
  590.       "Common Lisp and Artificial Intelligence"
  591.       Prentice Hall, Englewood Clifs, NJ, 1990. 244 pages. ISBN 0-13-155243.
  592.  
  593.    9. Paul Graham
  594.       "On Lisp: Advanced Techniques for Common Lisp"
  595.       Prentice Hall, Englewood Clifs, NJ, 1994. 400 pages, ISBN 0-13-030552-9.
  596.          Emphasizes a bottom-up style of writing programs, which he
  597.          claims is natural in Lisp and has advantages over the
  598.          traditional way of writing programs in C and Pascal.
  599.          Also has in-depth sections on writing macros with several
  600.          nice examples. Source code is available by anonymous ftp from
  601.             endor.harvard.edu:/pub/onlisp/ 
  602.          as a single 56kb file.
  603.  
  604. General Lisp reference books include:
  605.  
  606.    1. Guy L. Steele
  607.       "Common Lisp: The Language" [CLtL1]
  608.       Digital Press, 1984. 465 pages. ISBN 0-932376-41-X.
  609.  
  610.    2. Guy L. Steele
  611.       "Common Lisp: The Language, 2nd Edition" [CLtL2]
  612.       Digital Press, 1990. 1029 pages, ISBN 1-55558-041-6 paperbound ($39.95).
  613.  
  614.       [Butterworth-Heinemann, the owners of Digital Press, have made
  615.        the LaTeX sources to this book available by anonymous FTP from
  616.           cambridge.apple.com:/pub/CLTL/ 
  617.        A copy of the distribution is also available from
  618.           ftp.cs.cmu.edu:/user/ai/lang/lisp/doc/cltl/
  619.        The paperbound version of the book is, of course, available at
  620.        fine bookstores, or contact them directly at Digital Press, 
  621.        80 Montvale Avenue, Stoneham, MA 02180, call 800-366-2665
  622.        (617-928-2500), or fax 800-446-6520 (617-933-6333). A copy of
  623.        the Digital Press book catalog is available from the same FTP location.]
  624.  
  625.        A html version, produces using latex2html on the latex sources,
  626.        is accessible via the URL:
  627.            http://www.dcs.gla.ac.uk/~alison/clm/clm.html
  628.  
  629.    3. Franz Inc. 
  630.       "Common Lisp: The Reference"
  631.       Addison-Wesley, Reading, MA 1988. ISBN 0-201-11458-5
  632.            Entries on Lisp (CLtL1) functions in alphabetical order.
  633.  
  634. Lisp periodicals include:
  635.         
  636.    1. LISP Pointers.
  637.       Published by ACM SIGPLAN six times a year. Volume 1, Number 1
  638.       was April-May 1987. 
  639.       Subscriptions: ACM Members $12; ACM Student Members $7; Non-ACM
  640.       members $25. Mail checks payable to the ACM to ACM Inc., PO Box
  641.       12115, Church Street Station, New York, NY 10249.
  642.  
  643.    2. LISP and Symbolic Computation, Kluwer Academic Press. Volume 1
  644.       was published in 1989. (jlz@lucid.com is the editor).  ISSN 0892-4635.
  645.       Subscriptions: Institutions $169; Individuals $80. Add $8 for
  646.       air mail. Kluwer Academic Publishers, PO Box 322, 3300 AH Dordrecht, 
  647.       The Netherlands, or Kluwer Academic Publishers, PO Box 358, Accord
  648.       Station, Hingham, MA 02018-0358. 
  649.  
  650.       A full table of contents of all published issues, aims and scope, and
  651.       instructions for authors are available by anonymous ftp from
  652.          ftp.std.com:/Kluwer/journals/
  653.       as the files lisp.toc and lisp.inf.
  654.  
  655.    3. Proceedings of the biannual ACM Lisp and Functional Programming
  656.       Conference. (First one was in 1980.)
  657.  
  658.    4. Proceedings of the annual Lisp Users and Vendors Conference.
  659.  
  660. Implementation-specific questions:
  661.  
  662.    1. Lucid. See the wizards.doc file that comes with the Lucid
  663.       release. It describes functions, macros, variables and constants that
  664.       are not official parts of the product and are not supported.
  665.       Constructs described in this file include: the interrupt facility, the
  666.       source file recording facility, the resource facility, multitasking,
  667.       writing your own streams, lisp pipes, i/o buffers, the compiler,
  668.       floating-point functions, memory management, debugger information, the
  669.       window tool kit, extensions to the editor, the foreign function
  670.       interface, clos information, delivery toolkit information, and Lucid
  671.       lisp training classes. The wizards.doc file also covers i/o
  672.       constructs, functions for dealing with DEFSTRUCT, functions and
  673.       constants for dealing with procedure objects, functions and constants
  674.       for dealing with code objects, function for mapping objects,
  675.       additional keyword argument to DISKSAVE, function used in the
  676.       implementation of arrays, function for monitor-specific behavior for a
  677.       process, additional keyword argument to RUN-PROGRAM, and load-time
  678.       evaluation.
  679.  
  680. Many books on Scheme are worth reading even if you use Common Lisp,
  681. because many of the issues are similar. Scheme is a simpler language
  682. to learn, so it is often used in introductory computer science
  683. classes.  See the Scheme FAQ for a list of introductions and
  684. references for Scheme. The two key introductions are Abelson and
  685. Sussman's "Structure and Interpretation of Computer Programs" and 
  686. Friedman and Felleisen's "The Little LISPer". 
  687.  
  688. Special Topics:
  689.  
  690.    Garbage Collection:
  691.  
  692.       Wilson, Paul R., "Uniprocessor Garbage Collection Techniques"
  693.       Proceedings of the 1992 International Workshop on Memory Management.
  694.       Springer Lecture Notes #637. Surveys garbage collection techniques. 
  695.       Includes an excellent bibliography. Available by anonymous ftp from
  696.          cs.utexas.edu:/pub/garbage/gcsurvey.ps.
  697.       The BibTeX format of the bibliography is also available in this
  698.       directory, along with several other papers. Contact wilson@cs.utexas.edu
  699.       for more info.
  700.  
  701. ----------------------------------------------------------------
  702. Subject: [1-3] How can I improve my Lisp programming style and 
  703.                coding efficiency?
  704.  
  705. There are several books about Lisp programming style, including:
  706.    
  707.    1. Molly M. Miller and Eric Benson
  708.       "Lisp Style and Design"
  709.       Digital Press, 1990. 214 pages. ISBN 1-55558-044-0.
  710.            How to write large Lisp programs and improve Lisp programming 
  711.            style. Uses the development of Lucid CL as an example. 
  712.  
  713.    2. Robin Jones, Clive Maynard, and Ian Stewart.
  714.       "The Art of Lisp Programming"
  715.       Springer-Verlag, 1989. 169 pages, ISBN 0-387-19568-8 ($33).
  716.  
  717.    3. W. Richard Stark.
  718.       "LISP, Lore, and Logic: An Algebraic View of LISP
  719.        Programming, Foundations, and Applications"
  720.       Springer-Verlag, 1990. 278 pages. ISBN 0-387-97072-X paper ($42).
  721.            Self-modifying code, self-reproducing programs, etc.
  722.  
  723.    4. CMU CL User's Manual, Chapter 7, (talks about writing
  724.       efficient code). It is available by anonymous ftp from any CMU CS 
  725.       machine (e.g., ftp.cs.cmu.edu [128.2.206.173]) as the file
  726.         /afs/cs.cmu.edu/project/clisp/docs/cmu-user/cmu-user.ps 
  727.       [when getting this file by anonymous ftp, one must cd to 
  728.       the directory in one atomic operation, as some of the superior
  729.       directories on the path are protected from access by anonymous ftp.]
  730.  
  731.    5. See also Norvig's book, SICP (Abelson & Sussman), SAP
  732.       (Springer and Friedman).
  733.  
  734.    6. Hallvard Tretteberg's Lisp Style Guide is available by anonymous
  735.       ftp in ftp.think.com:/public/think/lisp/style-guide.text. There is
  736.       a fair bit of overlap between Hallvard's style guide and the notes
  737.       below and in part 3 of this FAQ.
  738.  
  739.    7. Rajeev Sangal
  740.       "Programming Paradigms in Lisp"
  741.       McGraw-Hill, 1991. ISBN 0-07-054666-5.
  742.  
  743.    8. Rodney A. Brooks.
  744.       "Programming in Common Lisp"
  745.       John Wiley & Sons, New York, 1985. 303 pages. ISBN 0-471-81888-7.
  746.       Chapter 5 discusses Lisp programming style.
  747.  
  748. Here are some general suggestions/notes about improving Lisp
  749. programming style, readability, correctness and efficiency:
  750.  
  751.    General Programming Style Rules:
  752.  
  753.       - Write short functions, where each function provides a single,
  754.         well-defined operation. Small functions are easier to
  755.         read, write, test, debug, and understand.
  756.  
  757.       - Use descriptive variable and function names. If it isn't clear
  758.         from the name of a function or variable what its purpose is,
  759.         document it with a documentation string and a comment. In fact,
  760.         even if the purpose is evident from the name, it is still worth
  761.         documenting your code.
  762.  
  763.       - Don't write Pascal (or C) code in Lisp. Use the appropriate
  764.         predefined functions -- look in the index to CLtL2, or use the
  765.         APROPOS and DESCRIBE functions. Don't put a close parenthesis
  766.         on a line by itself -- this can really aggravate programmers
  767.         who grew up on Lisp. Lisp-oriented text editors include tools
  768.         for ensuring balanced parentheses and for moving across 
  769.         pairs of balanced parentheses. You don't need to stick
  770.         comments on close parentheses to mark which expression they close.
  771.  
  772.       - Use proper indentation -- you should be able to understand
  773.         the structure of your definitions without noticing the parentheses. 
  774.         In general, the way one indents a form is controlled by the
  775.         first symbol of the form. In DEFUNs, for example, one puts the
  776.         symbol DEFUN, the function name, and the argument list all on
  777.         the same line. If the argument list is too long, one can break
  778.         it at one of the lambda keywords. Following the argument list,
  779.         one inserts a carriage return and lists the expressions in the
  780.         body of the definition, with each form starting on its own
  781.         line indented three spaces relative to the open parenthesis of
  782.         the parent (in this case the DEFUN). This general style -- of
  783.         putting all the significant elements of a form on a single
  784.         line, followed by a carriage return and the indented body --
  785.         holds for many Lisp constructs. There are, of course, variations,
  786.         such as keeping the first clause on the same line as the COND
  787.         or CASE symbol, and the rules are relaxed in different ways to
  788.         keep line lengths to a manageable size. If you find yourself having
  789.         trouble fitting everything in even with line breaking and
  790.         relaxing the rules, either your function names are too long or your
  791.         code isn't very modular. You should perceive this as a signal that
  792.         you need to break up your big definitions into smaller chunks, each
  793.         with a clearly defined purpose, and possibly replace long function
  794.         names with concise but apt shorter ones.
  795.  
  796.       - Use whitespace appropriately. Use whitespace to separate
  797.         semantically distinct code segments, but don't use too much
  798.         whitespace. For example,
  799.            GOOD: 
  800.               (defun foo (x y)
  801.                 (let ((z (+ x y 10)))
  802.                   (* z z)))
  803.  
  804.            BAD: 
  805.               (defun foo(x y)(let((z(+ x y 10)))(* z z)))
  806.  
  807.               (defun foo ( x  y )
  808.                 (let ( ( z (+ x y 10) ) )
  809.                   ( * z z )
  810.                   )
  811.                 )    
  812.          Although the Lisp reader and compiler don't care which you
  813.          use, most experienced Lisp programs find the first example much easier
  814.          to read than the last two.
  815.  
  816.        - Don't use line lengths greater than 80 characters. People who
  817.          write code using Zmacs on Symbolics Lisp Machines are notoriously
  818.          guilty of violating this rule, because the CPT6 font allows
  819.          one to squeeze a tremendous amount of code on the display,
  820.          especially if one spreads the code out horizontally. This
  821.          makes it more difficult to read when printed out or read on
  822.          an 80x24 xterm window. In fact, use a line length of 72 characters
  823.          because it leaves a strip of white space at the edge of the window.
  824.  
  825.    The following functions often abused or misunderstood by novices. 
  826.    Think twice before using any of these functions.
  827.  
  828.       - EVAL. Novices almost always misuse EVAL. When experts use
  829.         EVAL, they often would be better off using APPLY, FUNCALL, or
  830.         SYMBOL-VALUE. Use of EVAL when defining a macro should set off
  831.         a warning bell -- macro definitions are already evaluated
  832.         during expansion. See also the answer to question 3-12.
  833.         The general rule of thumb about EVAL is: if you think you need
  834.         to use EVAL, you're probably wrong.
  835.  
  836.       - PROGV. PROGV binds dynamic variables and is often misused in
  837.         conjunction with EVAL, which uses the dynamic environment. 
  838.         In general, avoid unnecessary use of special variables.
  839.         PROGV is mainly for writing interpreters for languages embedded
  840.         in Lisp. If you want to bind a list of values to a list of
  841.         lexical variables, use
  842.             (MULTIPLE-VALUE-BIND (..) (VALUES-LIST ..) ..)
  843.         or
  844.             (MULTIPLE-VALUE-SETQ (..) (VALUES-LIST ..))
  845.         instead. Most decent compilers can optimize this expression. 
  846.         However, use of this idiom is not to be encouraged unless absolutely
  847.         necessary.
  848.  
  849.       - CATCH and THROW. Often a named BLOCK and RETURN-FROM are
  850.         more appropriate. Use UNWIND-PROTECT when necessary.
  851.  
  852.       - Destructive operations, such as NCONC, SORT, DELETE,
  853.         RPLACA, and RPLACD, should be used carefully and sparingly.
  854.         In general, trust the garbage collector: allocate new
  855.         data structures when you need them.
  856.  
  857.    To improve the readability of your code,
  858.  
  859.       - Don't use any C{A,D}R functions with more than two
  860.         letters between the C and the R. When nested, they become
  861.         hard to read. If you have complex data structures, you
  862.         are often better off describing them with a DEFSTRUCT,
  863.         even if the type is LIST. The data abstraction afforded by
  864.         DEFSTRUCT makes the code much more readable and its purpose
  865.         clearer. If you must use C{A,D}R, try to use
  866.         DESTRUCTURING-BIND instead, or at least SECOND, THIRD, 
  867.         NTH, NTHCDR, etc.
  868.  
  869.       - Use COND instead of IF and PROGN. In general, don't use PROGN if
  870.         there is a way to write the code within an implicit
  871.         PROGN. For example, 
  872.            (IF (FOO X)
  873.                (PROGN (PRINT "hi there") 23)
  874.                34)
  875.         should be written using COND instead.
  876.  
  877.       - Never use a 2-argument IF or a 3-argument IF with a second
  878.         argument of NIL unless you want to emphasize the return value;
  879.         use WHEN and UNLESS instead. You will want to emphasize the
  880.         return value when the IF clause is embedded within a SETQ,
  881.         such as (SETQ X (IF (EQ Y Z) 2 NIL)). If the second argument 
  882.         to IF is the same as the first, use OR instead: (OR P Q) rather
  883.         than (IF P P Q). Use UNLESS instead of (WHEN (NOT ..) ..)
  884.         but not instead of (WHEN (NULL ..) ..).
  885.  
  886.       - Use COND instead of nested IF statements. Be sure to check for
  887.         unreachable cases, and eliminate those cond-clauses.
  888.  
  889.       - Use backquote, rather than explicit calls to LIST, CONS, and
  890.         APPEND, whenever writing a form which produces a Lisp form, but
  891.         not as a general substitute for LIST, CONS and APPEND. LIST, 
  892.         CONS and APPEND usually allocate new storage, but lists produced
  893.         by backquote may involve destructive modification (e.g., ,.).
  894.  
  895.       - Make the names of special (global) variables begin and end
  896.         with an asterisk (*): (DEFVAR *GLOBAL-VARIABLE*)   
  897.         Some programmers will mark the beginning and end of an internal
  898.         global variable with a percent (%) or a period (.).
  899.         Make the names of constants begin and end with a plus (+):
  900.         (DEFCONSTANT +E+ 2.7182818)
  901.         This helps distinguish them from lexical variables. Some people
  902.         prefer to use macros to define constants, since this avoids
  903.         the problem of accidentally trying to bind a symbol declared
  904.         with defconstant.
  905.  
  906.       - If your program is built upon an underlying substrate which is
  907.         implementation-dependent, consider naming those functions and
  908.         macros in a way that visually identifies them, either by placing
  909.         them in their own package, or prepending a character like a %, ., 
  910.         or ! to the function name. Note that many programmers use the
  911.         $ as a macro character for slot access, so it should be avoided
  912.         unless you're using it for that purpose.
  913.  
  914.       - Don't use property lists. Instead, use an explicit hash table.
  915.         This helps avoid problems caused by the symbol being in the wrong
  916.         package, accidental reuse of property keys from other
  917.         programs, and allows you to customize the structure of the table. 
  918.  
  919.       - Use the most specific construct that does the job. This lets
  920.         readers of the code see what you intended when writing the code.
  921.         For example, don't use SETF if SETQ will do (e.g., for lexical
  922.         variables). Using SETQ will tell readers of your code that you
  923.         aren't doing anything fancy. Likewise, don't use EQUAL where EQ
  924.         will do. Use the most specific predicate to test your conditions. 
  925.         
  926.       - If you intend for a function to be a predicate, have it return T
  927.         for true, not just non-NIL. If there is nothing worth returning
  928.         from a function, returning T is conventional. But if a function
  929.         is intended to be more than just a predicate, it is better to 
  930.         return a useful value. (For example, this is one of the differences
  931.         between MEMBER and FIND.)
  932.  
  933.       - When NIL is used as an empty list, use () in your code. When NIL
  934.         is used as a boolean, use NIL. Similarly, use NULL to test for an
  935.         empty list, NOT to test a logical value. Use ENDP to test for the
  936.         end of a list, not NULL.
  937.  
  938.       - Don't use the &AUX lambda-list keyword. It is always clearer to
  939.         define local variables using LET or LET*.
  940.  
  941.       - When using RETURN and RETURN-FROM to exit from a block, don't
  942.         use (VALUES ..) when returning only one value, except if you
  943.         are using it to suppress extra multiple values from the first
  944.         argument. 
  945.  
  946.       - If you want a function to return no values (i.e., equivalent to
  947.         VOID in C), use (VALUES) to return zero values. This signals
  948.         to the reader that the function is used mainly for side-effects.
  949.  
  950.       - (VALUES (VALUES 1 2 3)) returns only the first value, 1.
  951.         You can use (VALUES (some-multiple-value-function ..)) to suppress
  952.         the extra multiple values from the function. Use MULTIPLE-VALUE-PROG1
  953.         instead of PROG1 when the multiple values are significant.
  954.  
  955.       - When using MULTIPLE-VALUE-BIND and DESTRUCTURING-BIND, don't rely
  956.         on the fact that NIL is used when values are missing. This is
  957.         an error in some implementations of DESTRUCTURING-BIND. Instead,
  958.         make sure that your function always returns the proper number of
  959.         values.
  960.  
  961.       - Type the name of external symbols, functions, and variables
  962.         from the COMMON-LISP package in uppercase. This will allow your
  963.         code to work properly in a case-sensitive version of Common Lisp,
  964.         since the print-names of symbols in the COMMON-LISP package
  965.         are uppercase internally. (However, not everybody feels that
  966.         being nice to case-sensitive Lisps is a requirement, so this
  967.         isn't an absolute style rule, just a suggestion.)
  968.  
  969.     Lisp Idioms:
  970.  
  971.       - MAPCAN is used with a function to return a variable number of
  972.         items to be included in an output list. When the function returns zero
  973.         or one items, the function serves as a filter. For example,
  974.            (mapcan #'(lambda (x) (when (and (numberp x) (evenp x)) (list x)))
  975.                    '(1 2 3 4 x 5 y 6 z 7))
  976.  
  977.     Documentation:
  978.  
  979.       - Comment your code. Use three semicolons in the left margin before
  980.         the definition for major explanations. Use two semicolons that
  981.         float with the code to explain the routine that follows. Two
  982.         semicolons may also be used to explain the following line when the
  983.         comment is too long for the single semicolon treatment. Use
  984.         a single semicolon to the right of the code to explain a particular
  985.         line with a short comment. The number of semicolons used roughly
  986.         corresponds with the length of the comment. Put at least one blank
  987.         line before and after top-level expressions.
  988.  
  989.       - Include documentation strings in your code. This lets users
  990.         get help while running your program without having to resort to
  991.         the source code or printed documentation. 
  992.  
  993.    Issues related to macros:
  994.  
  995.       - Never use a macro instead of a function for efficiency reasons.
  996.         Declaim the function as inline -- for example, 
  997.           (DECLAIM (INLINE ..))
  998.         This is *not* a magic bullet -- be forewarned that inline
  999.         expansions can often increase the code size dramatically. INLINE
  1000.         should be used only for short functions where the tradeoff is
  1001.         likely to be worthwhile: inner loops, types that the compiler
  1002.         might do something smart with, and so on.
  1003.  
  1004.       - When defining a macro that provides an implicit PROGN, use the
  1005.         &BODY lambda-list keyword instead of &REST.
  1006.  
  1007.       - Use gensyms for bindings within a macro, unless the macro lets
  1008.         the user explicitly specify the variable. For example:
  1009.             (defmacro foo ((iter-var list) body-form &body body)
  1010.               (let ((result (gensym "RESULT")))
  1011.                 `(let ((,result nil))
  1012.                    (dolist (,iter-var ,list ,result)
  1013.                      (setq ,result ,body-form)
  1014.                      (when ,result
  1015.                         ,@body)))))        
  1016.         This avoids errors caused by collisions during macro expansion
  1017.         between variable names used in the macro definition and in the
  1018.         supplied body.
  1019.  
  1020.       - Use a DO- prefix in the name of a macro that does some kind of
  1021.         iteration, WITH- when the macro establishes bindings, and
  1022.         DEFINE- or DEF- when the macro creates some definitions. Don't
  1023.         use the prefix MAP- in macro names, only in function names.
  1024.  
  1025.       - Don't create a new iteration macro when an existing function
  1026.         or macro will do.
  1027.  
  1028.       - Don't define a macro where a function definition will work just
  1029.         as well -- remember, you can FUNCALL or MAPCAR a function but 
  1030.         not a macro.
  1031.  
  1032.       - The LOOP and SERIES macros generate efficient code. If you're
  1033.         writing a new iteration macro, consider learning to use one
  1034.         of them instead.
  1035.   
  1036.    File Modularization:
  1037.  
  1038.       - If your program involves macros that are used in more than one
  1039.         file, it is generally a good idea to put such macros in a separate
  1040.         file that gets loaded before the other files. The same things applies
  1041.         to primitive functions. If a macro is complicated, the code that
  1042.         defines the macro should be put into a file by itself. In general, if
  1043.         a set of definitions form a cohesive and "independent" whole, they
  1044.         should be put in a file by themselves, and maybe even in their own
  1045.         package. It isn't unusual for a large Lisp program to have files named
  1046.         "site-dependent-code", "primitives.lisp", and "macros.lisp". If a file
  1047.         contains primarily macros, put "-macros" in the name of the file.
  1048.  
  1049.    Stylistic preferences:
  1050.  
  1051.       - Use (SETF (CAR ..) ..) and (SETF (CDR ..) ..) in preference to
  1052.         RPLACA and RPLACD. Likewise (SETF (GET ..) ..) instead of PUT.
  1053.  
  1054.       - Use INCF, DECF, PUSH and POP instead instead of the corresponding
  1055.         SETF forms.
  1056.  
  1057.       - Many programmers religiously avoid using CATCH, THROW, BLOCK,
  1058.         PROG, GO and TAGBODY.  Tags and go-forms should only be necessary
  1059.         to create extremely unusual and complicated iteration constructs. In
  1060.         almost every circumstance, a ready-made iteration construct or
  1061.         recursive implementation is more appropriate.
  1062.  
  1063.       - Don't use LET* where LET will do. Don't use LABELS where FLET
  1064.         will do. Don't use DO* where DO will do.
  1065.  
  1066.       - Don't use DO where DOTIMES or DOLIST will do.
  1067.  
  1068.       - If you like using MAPCAR instead of DO/DOLIST, use MAPC when
  1069.         no result is needed -- it's more efficient, since it doesn't
  1070.         cons up a list. If a single cumulative value is required, use
  1071.         REDUCE. If you are seeking a particular element, use FIND,
  1072.         POSITION, or MEMBER.
  1073.  
  1074.       - If using REMOVE and DELETE to filter a sequence, don't use the
  1075.         :test-not keyword or the REMOVE-IF-NOT or DELETE-IF-NOT functions.
  1076.         Use COMPLEMENT to complement the predicate and the REMOVE-IF
  1077.         or DELETE-IF functions instead.
  1078.  
  1079.       - Use complex numbers to represent points in a plane.
  1080.  
  1081.       - Don't use lists where vectors are more appropriate. Accessing the
  1082.         nth element of a vector is faster than finding the nth element
  1083.         of a list, since the latter requires pointer chasing while the
  1084.         former requires simple addition. Vectors also take up less space
  1085.         than lists. Use adjustable vectors with fill-pointers to
  1086.         implement a stack, instead of a list -- using a list continually
  1087.         conses and then throws away the conses.
  1088.  
  1089.       - When adding an entry to an association list, use ACONS, not
  1090.         two calls to CONS. This makes it clear that you're using an alist.
  1091.  
  1092.       - If your association list has more than about 10 entries in it,
  1093.         consider using a hash table. Hash tables are often more efficient.
  1094.         (See also [2-2].)
  1095.  
  1096.       - When you don't need the full power of CLOS, consider using
  1097.         structures instead. They are often faster, take up less space, and
  1098.         easier to use.
  1099.  
  1100.       - Use PRINT-UNREADABLE-OBJECT when writing a print-function.
  1101.  
  1102.       - Use WITH-OPEN-FILE instead of OPEN and CLOSE.
  1103.  
  1104.       - When a HANDLER-CASE clause is executed, the stack has already
  1105.         unwound, so dynamic bindings that existed when the error
  1106.         occured may no longer exist when the handler is run. Use
  1107.         HANDLER-BIND if you need this. 
  1108.  
  1109.       - When using CASE and TYPECASE forms, if you intend for the form
  1110.         to return NIL when all cases fail, include an explicit OTHERWISE
  1111.         clause. If it would be an error to return NIL when all cases
  1112.         fail, use ECASE, CCASE, ETYPECASE or CTYPECASE instead.
  1113.  
  1114.       - Use local variables in preference to global variables whenever
  1115.         possible. Do not use global variables in lieu of parameter passing.
  1116.         Global variables can be used in the following circumstances:
  1117.           *  When one function needs to affect the operation of
  1118.              another, but the second function isn't called by the first.
  1119.              (For example, *load-pathname* and *break-on-warnings*.)
  1120.           *  When a called function needs to affect the current or future
  1121.              operation of the caller, but it doesn't make sense to accomplish
  1122.              this by returning multiple values.
  1123.           *  To provide hooks into the mechanisms of the program.
  1124.              (For example, *evalhook*, *, /, and +.)
  1125.           *  Parameters which, when their value is changed, represent a
  1126.              major change to the program.
  1127.              (For example, *print-level* and *print-readably*.)
  1128.           *  For state that persists between invocations of the program.
  1129.              Also, for state which is used by more than one major program.
  1130.              (For example, *package*, *readtable*, *gensym-counter*.)
  1131.           *  To provide convenient information to the user.
  1132.              (For example, *version* and *features*.)
  1133.           *  To provide customizable defaults. 
  1134.              (For example, *default-pathname-defaults*.)
  1135.           *  When a value affects major portions of a program, and passing
  1136.              this value around would be extremely awkward. (The example
  1137.              here is output and input streams for a program. Even when
  1138.              the program passes the stream around as an argument, if you
  1139.              want to redirect all output from the program to a different
  1140.              stream, it is much easier to just rebind the global variable.)
  1141.  
  1142.       - Beginning students, especially ones accustomed to programming
  1143.         in C, Pascal, or Fortran, tend to use global variables to hold or pass
  1144.         information in their programs. This style is considered ugly by
  1145.         experienced Lisp programmers. Although assignment statements can't
  1146.         always be avoided in production code, good programmers take advantage
  1147.         of Lisp's functional programming style before resorting to SETF and
  1148.         SETQ. For example, they will nest function calls instead of using a
  1149.         temporary variable and use the stack to pass multiple values. When
  1150.         first learning to program in Lisp, try to avoid SETF/SETQ and their
  1151.         cousins as much as possible. And if a temporary variable is necessary,
  1152.         bind it to its first value in a LET statement, instead of letting it
  1153.         become a global variable by default. (If you see lots of compiler
  1154.         warnings about declaring variables to be special, you're probably
  1155.         making this mistake. If you intend a variable to be global, it should
  1156.         be defined with a DEFVAR or DEFPARAMETER statement, not left to the
  1157.         compiler to fix.)
  1158.  
  1159.    Correctness and efficiency issues:
  1160.  
  1161.       - In CLtL2, IN-PACKAGE does not evaluate its argument. Use defpackage
  1162.         to define a package and declare the external (exported)
  1163.         symbols from the package. 
  1164.  
  1165.       - The ARRAY-TOTAL-SIZE-LIMIT may be as small as 1024, and the
  1166.         CALL-ARGUMENTS-LIMIT may be as small as 50. 
  1167.  
  1168.       - Novices often mistakenly quote the conditions of a CASE form.
  1169.         For example, (case x ('a 3) ..) is incorrect. It would return
  1170.         3 if x were the symbol QUOTE. Use (case x (a 3) ..) instead.
  1171.  
  1172.       - Avoid using APPLY to flatten lists. Although 
  1173.            (apply #'append list-of-lists)
  1174.         may look like a call with only two arguments, it becomes a 
  1175.         function call to APPEND, with the LIST-OF-LISTS spread into actual
  1176.         arguments. As a result it will have as many arguments as there are
  1177.         elements in LIST-OF-LISTS, and hence may run into problems with the
  1178.         CALL-ARGUMENTS-LIMIT. Use REDUCE or MAPCAN instead:  
  1179.            (reduce #'append list-of-lists :from-end t)
  1180.            (mapcan #'copy-list list-of-lists)
  1181.         The second will often be more efficient (see note below about choosing
  1182.         the right algorithm). Beware of calls like (apply f (mapcar ..)).
  1183.  
  1184.       - NTH must cdr down the list to reach the elements you are
  1185.         interested in. If you don't need the structural flexibility of
  1186.         lists, try using vectors and the ELT function instead.
  1187.  
  1188.       - CASE statements can be vectorized if the keys are consecutive
  1189.         numbers. Such CASE statements can still have OTHERWISE clauses.
  1190.         To take advantage of this without losing readability, use #. with 
  1191.         symbolic constants:
  1192.  
  1193.             (eval-when (compile load eval)
  1194.                (defconstant RED 1)
  1195.                (defconstant GREEN 2)
  1196.                (defconstant BLUE 3))
  1197.  
  1198.             (case color
  1199.               (#.RED   ...)
  1200.               (#.GREEN ...)
  1201.               (#.BLUE  ...)
  1202.               ...)
  1203.  
  1204.       - Don't use quoted constants where you might later destructively
  1205.         modify them. For example, instead of writing '(c d) in
  1206.            (defun foo ()
  1207.              (let ((var '(c d)))
  1208.                ..))
  1209.         write (list 'c 'd) instead. Using a quote here can lead to
  1210.         unexpected results later. If you later destructively modify the 
  1211.         value of var, this is self-modifying code! Some Lisp compilers
  1212.         will complain about this, since they like to make constants
  1213.         read-only. Modifying constants has undefined results in ANSI CL.
  1214.         See also the answer to question [3-13].
  1215.  
  1216.         Similarly, beware of shared list structure arising from the use
  1217.         of backquote. Any sublist in a backquoted expression that doesn't
  1218.         contain any commas can share with the original source structure.
  1219.  
  1220.       - Don't proclaim unsafe optimizations, such as
  1221.            (proclaim '(optimize (safety 0) (speed 3) (space 1))) 
  1222.         since this yields a global effect. Instead, add the
  1223.         optimizations as local declarations to small pieces of
  1224.         well-tested, performance-critical code:
  1225.            (defun well-tested-function ()
  1226.               (declare (optimize (safety 0) (speed 3) (space 1)))
  1227.              ..)
  1228.         Such optimizations can remove run-time type-checking; type-checking
  1229.         is necessary unless you've very carefully checked your code
  1230.         and added all the appropriate type declarations.
  1231.  
  1232.       - Some programmers feel that you shouldn't add declarations to
  1233.         code until it is fully debugged, because incorrect
  1234.         declarations can be an annoying source of errors. They recommend
  1235.         using CHECK-TYPE liberally instead while you are developing the code.
  1236.         On the other hand, if you add declarations to tell the
  1237.         compiler what you think your code is doing, the compiler can
  1238.         then tell you when your assumptions are incorrect.
  1239.         Declarations also make it easier for another programmer to read
  1240.         your code. 
  1241.  
  1242.       - Declaring the type of variables to be FIXNUM does not
  1243.         necessarily mean that the results of arithmetic involving the 
  1244.         fixnums will be a fixnum; it could be a BIGNUM. For example,
  1245.            (declare (type fixnum x y))
  1246.            (setq z (+ (* x x) (* y y)))
  1247.         could result in z being a BIGNUM. If you know the limits of your
  1248.         numbers, use a declaration like
  1249.            (declare (type (integer 0 100) x y))
  1250.         instead, since most compilers can then do the appropriate type
  1251.         inference, leading to much faster code.
  1252.  
  1253.       - Don't change the compiler optimization with an OPTIMIZE
  1254.         proclamation or declaration until the code is fully debugged
  1255.         and profiled.  When first writing code you should say 
  1256.         (declare (optimize (safety 3))) regardless of the speed setting.
  1257.  
  1258.       - Depending on the optimization level of the compiler, type
  1259.         declarations are interpreted either as (1) a guarantee from
  1260.         you that the variable is always bound to values of that type,
  1261.         or (2) a desire that the compiler check that the variable is
  1262.         always bound to values of that type. Use CHECK-TYPE if (2) is
  1263.         your intention.
  1264.  
  1265.       - If you get warnings about unused variables, add IGNORE
  1266.         declarations if appropriate or fix the problem. Letting such
  1267.         warnings stand is a sloppy coding practice.
  1268.  
  1269.    To produce efficient code,
  1270.  
  1271.       - choose the right algorithm. For example, consider seven possible
  1272.         implementations of COPY-LIST:
  1273.  
  1274.            (defun copy-list (list)
  1275.              (let ((result nil))
  1276.                (dolist (item list result)
  1277.                  (setf result (append result (list item))))))
  1278.  
  1279.            (defun copy-list (list)
  1280.              (let ((result nil))
  1281.                (dolist (item list (nreverse result))
  1282.                  (push item result))))
  1283.  
  1284.            (defun copy-list (list)
  1285.              (mapcar #'identity list))
  1286.  
  1287.            (defun copy-list (list)
  1288.              (let ((result (make-list (length list))))
  1289.                (do ((original list (cdr original))
  1290.                     (new result (cdr new)))
  1291.                    ((null original) result)
  1292.                  (setf (car new) (car original)))))
  1293.  
  1294.            (defun copy-list (list)
  1295.              (when list
  1296.                (let* ((result (list (car list)))
  1297.                       (tail-ptr result))
  1298.                  (dolist (item (cdr list) result)
  1299.                    (setf (cdr tail-ptr) (list item))
  1300.                    (setf tail-ptr (cdr tail-ptr))))))
  1301.         
  1302.             (defun copy-list (list)
  1303.               (loop for item in list collect item))
  1304.  
  1305.             (defun copy-list (list)
  1306.               (if (consp list) 
  1307.                   (cons (car list)
  1308.                         (copy-list (cdr list)))
  1309.                   list))
  1310.  
  1311.         The first uses APPEND to tack the elements onto the end of the list.
  1312.         Since APPEND must traverse the entire partial list at each step, this
  1313.         yields a quadratic running time for the algorithm.  The second
  1314.         implementation improves on this by iterating down the list twice; once
  1315.         to build up the list in reverse order, and the second time to reverse
  1316.         it. The efficiency of the third depends on the Lisp implementation,
  1317.         but it is usually similar to the second, as is the fourth.  The fifth
  1318.         algorithm, however, iterates down the list only once. It avoids the
  1319.         extra work by keeping a pointer (reference) to the last cons of the 
  1320.         list and RPLACDing onto the end of that. Use of the fifth algorithm 
  1321.         may yield a speedup. Note that this contradicts the earlier dictum to
  1322.         avoid destructive functions. To make more efficient code one might
  1323.         selectively introduce destructive operations in critical sections of
  1324.         code. Nevertheless, the fifth implementation may be less efficient in
  1325.         Lisps with cdr-coding, since it is more expensive to RPLACD cdr-coded
  1326.         lists. Depending on the implementation of nreverse, however,
  1327.         the fifth and second implementations may be doing the same
  1328.         amount of work. The sixth example uses the Loop macro, which usually
  1329.         expands into code similar to the third. The seventh example copies
  1330.         dotted lists, and runs in linear time, but isn't tail-recursive. 
  1331.  
  1332.       - use type declarations liberally in time-critical code, but
  1333.         only if you are a seasoned Lisp programmer. Appropriate type
  1334.         declarations help the compiler generate more specific and
  1335.         optimized code. It also lets the reader know what assumptions
  1336.         were made. For example, if you only use fixnum arithmetic,
  1337.         adding declarations can lead to a significant speedup. If you
  1338.         are a novice Lisp programmer, you should use type declarations
  1339.         sparingly, as there may be no checking to see if the
  1340.         declarations are correct, and optimized code can be harder to
  1341.         debug. Wrong declarations can lead to errors in otherwise
  1342.         correct code, and can limit the reuse of code in other
  1343.         contexts. Depending on the Lisp compiler, it may also 
  1344.         be necessary to declare the type of results using THE, since
  1345.         some compilers don't deduce the result type from the inputs.
  1346.  
  1347.       - check the code produced by the compiler by using the
  1348.         disassemble function
  1349.  
  1350. ----------------------------------------------------------------
  1351. Subject: [1-4] Where can I learn about implementing Lisp interpreters 
  1352.                and compilers?
  1353.  
  1354. Books about Lisp implementation include:
  1355.  
  1356.    1. John Allen
  1357.       "Anatomy of Lisp"
  1358.       McGraw-Hill, 1978. 446 pages. ISBN 0-07-001115-X
  1359.            Discusses some of the fundamental issues involved in
  1360.            the implemention of Lisp.  
  1361.  
  1362.    2. Samuel Kamin
  1363.       "Programming Languages, An Interpreter-Based Approach"
  1364.       Addison-Wesley, Reading, Mass., 1990. ISBN 0-201-06824-9
  1365.            Includes sources to several interpreters for Lisp-like languages.
  1366.            The source for the interpreters in the book is available
  1367.            by anonymous FTP from 
  1368.               a.cs.uiuc.edu:/pub/kamin/kamin.distr/
  1369.           Tim Budd reimplemented the interpreters in C++, and has made
  1370.           them available by anonymous ftp from 
  1371.               cs.orst.edu:/pub/budd/kamin/
  1372.  
  1373.    3. Sharam Hekmatpour
  1374.       "Lisp: A Portable Implementation"
  1375.       Prentice Hall, 1985. ISBN 0-13-537490-X.
  1376.            Describes a portable implementation of a small dynamic
  1377.            Lisp interpreter (including C source code). 
  1378.  
  1379.    4. Peter Henderson
  1380.       "Functional Programming: Application and Implementation"
  1381.       Prentice-Hall (Englewood Cliffs, NJ), 1980. 355 pages.
  1382.  
  1383.    5. Peter M. Kogge
  1384.       "The Architecture of Symbolic Computers"
  1385.       McGraw-Hill, 1991. ISBN 0-07-035596-7.
  1386.            Includes sections on memory management, the SECD and
  1387.            Warren Abstract Machines, and overviews of the various
  1388.            Lisp Machine architectures.
  1389.    
  1390.    6. Daniel P. Friedman, Mitchell Wand, and Christopher T. Haynes
  1391.       "Essentials of Programming Languages"
  1392.       MIT Press, 1992, 536 pages. ISBN 0-262-06145-7.
  1393.            Teaches fundamental concepts of programming language
  1394.            design by using small interpreters as examples. Covers
  1395.            most of the features of Scheme. Includes a discussion
  1396.            of parameter passing techniques, object oriented languages,
  1397.            and techniques for transforming interpreters to allow
  1398.            their implementation in terms of any low-level language.
  1399.            Also discusses scanners, parsers, and the derivation of
  1400.            a compiler and virtual machine from an interpreter.
  1401.            Includes a few chapters on converting code into a
  1402.            continuation passing style.
  1403.            Source files available by anonymous ftp from 
  1404.               cs.indiana.edu:/pub/eopl/ [129.79.254.191].
  1405.  
  1406.    7. Peter Lee, editor, "Topics in Advanced Language Implementation",
  1407.       The MIT Press, Cambridge, Mass., 1991.
  1408.            Articles relevant to the implementation of functional
  1409.            programming languages.
  1410.  
  1411.    8. Also see the proceedings of the biannual ACM Lisp and Functional
  1412.       Programming conferences, the implementation notes for CMU Common Lisp,
  1413.       Norvig's book, and SICP (Abelson & Sussman).
  1414.  
  1415.    9. Christian Queinnec
  1416.       "Les Langages Lisp"
  1417.       InterEditions (in French), 1994. 500 pages.
  1418.       ISBN 2-7296-0549-5, 61-2448-1. (?)
  1419.  
  1420.       The book covers Lisp, Scheme and other related dialects,
  1421.       their interpretation, semantics and compilation.
  1422.  
  1423.       All of the programs described in the book are available by
  1424.       anonymous ftp from
  1425.          ftp.inria.fr:/INRIA/Projects/icsla/Books/LiSP94Sep05.tar.gz
  1426.       For more information, see the book's URL
  1427.          file://ftp.inria.fr/INRIA/Projects/icsla/WWW/LiSP.html
  1428.       or contact the author at Christian.Queinnec@inria.fr
  1429.  
  1430. ----------------------------------------------------------------
  1431. Subject: [1-5] What is the "minimal" set of primitives needed for a Lisp
  1432.                interpreter? 
  1433.  
  1434. Many Lisp functions can be defined in terms of other Lisp functions.
  1435. For example, CAAR can be defined in terms of CAR as
  1436.    (defun caar (list) (car (car list)))
  1437. It is then natural to ask whether there is a "minimal" or smallest set
  1438. of primitives necessary to implement the language. 
  1439.  
  1440. There is no single "best" minimal set of primitives; it all depends on
  1441. the implementation. For example, even something as basic as numbers
  1442. need not be primitive, and can be represented as lists. One possible
  1443. set of primitives might include CAR, CDR, and CONS for manipulation of
  1444. S-expressions, READ and PRINT for the input/output of S-expressions
  1445. and APPLY and EVAL for the guts of an interpreter.  But then you might
  1446. want to add LAMBDA for functions, EQ for equality, COND for
  1447. conditionals, SET for assignment, and DEFUN for definitions. QUOTE
  1448. might come in handy as well. If you add more specialized datatypes,
  1449. such as integers, floats, arrays, characters, and structures, you'll
  1450. need to add primitives to construct and access each.
  1451.  
  1452. AWKLisp is a Lisp interpreter written in awk, available by anonymous
  1453. ftp from ftp.cs.cmu.edu:/user/ai/lang/lisp/impl/awk/. It has thirteen
  1454. built-in functions: CAR, CDR, CONS, EQ, ATOM, SET, EVAL, ERROR, QUOTE,
  1455. COND, AND, OR, LIST. 
  1456.  
  1457. A more practical notion of a "minimal" set of primitives might be to
  1458. look at the implementation of Scheme. While many Scheme functions can
  1459. be derived from others, the language is much smaller than Common Lisp.
  1460. See Dybvig's PhD thesis, 
  1461.    R. Kent Dybvig, "Three Implementation Models for Scheme", Department
  1462.    of Computer Science Technical Report #87-011, University of North
  1463.    Carolina at Chapel Hill, Chapel Hill, North Carolina, April 1987.
  1464. for a justification of a particularly practical minimal set of
  1465. primitives for Scheme.
  1466.  
  1467. In a language like Common Lisp, however, there are a lot of low-level
  1468. primitive functions that cannot be written in terms of the others,
  1469. such as GET-UNIVERSAL-TIME, READ-CHAR, WRITE-CHAR, OPEN, and CLOSE,
  1470. for starters.  Moreover, real Common Lisp implementations are often
  1471. built upon primitives that aren't part of the language, per se, and
  1472. certainly not intended to be user-accessible, such as SYS:%POINTER-REF.
  1473.  
  1474. Beside the references listed in [1-4], some other relevant references
  1475. include:  
  1476.  
  1477.     McCarthy, John, "Recursive Functions of Symbolic Expressions and
  1478.     their Computation by Machine, Part I", CACM 3(4):185-195, April 1960.
  1479.        [Defines five elementary functions on s-expressions.]
  1480.  
  1481.     McCarthy, John, "A Micro-Manual for Lisp -- not the whole Truth",
  1482.     ACM SIGPLAN Notices, 13(8):215-216, August 1978.
  1483.        [Defines the Lisp programming language in 10 rules and gives
  1484.         a small interpreter (eval) written in this Lisp.]
  1485.  
  1486.     McCarthy, John, et al., "LISP 1.5 Programmer's Manual", 2nd edition,
  1487.     MIT Press, 1965, ISBN 0-262-13011-4 (paperback).  
  1488.        [Gives five basic functions, CAR, CDR, CONS, EQ, and ATOM.
  1489.         Using composition, conditional expressions (COND), and
  1490.         recursion, LAMBDA, and QUOTE, these basic functions may be used
  1491.         to construct the entire class of computable functions of
  1492.         S-expressions. Gives the functions EVAL and APPLY in
  1493.         M-expression syntax.] 
  1494.  
  1495.     Abelson and Sussman's SICP, especially chapters 4 and 5 on the
  1496.     implementation of meta-circular and explicit-control evaluators.
  1497.  
  1498.     Steele and Gabriel's "The Evolution of LISP".
  1499.  
  1500. ----------------------------------------------------------------
  1501. Subject: [1-6]  What does CLOS, PCL, X3J13, CAR, CDR, ... mean? 
  1502.  
  1503. Glossary of acronyms:
  1504.    CAR             Originally meant "Contents of Address portion of Register",
  1505.                    which is what CAR actually did on the IBM 704.
  1506.    CDR             Originally meant "Contents of Decrement portion of 
  1507.                    Register", which is what CDR actually did
  1508.                    on the IBM 704. Pronounced "Cudder" /kUdd@r/ (as in "a cow
  1509.                    chews its cdr"). The first syllable is pronounced
  1510.                    like "could". 
  1511.    LISP            Originally from "LISt Processing"
  1512.    GUI             Graphical User Interface
  1513.    CLOS            Common Lisp Object System. The object oriented
  1514.                    programming standard for Common Lisp. Based on
  1515.                    Symbolics FLAVORS and Xerox LOOPS, among others.
  1516.                    Pronounced either as "See-Loss" or "Closs". See also PCL.
  1517.    PCL             Portable Common Loops. A portable CLOS implementation.
  1518.                    Available by anonymous ftp from parcftp.xerox.com:pcl/.
  1519.    LOOPS           Lisp Object Oriented Programming System. A predecessor
  1520.                    to CLOS on Xerox Lisp machines.
  1521.    X3J13           Subcommittee of the ANSI committee X3 which is
  1522.                    working on the ANSI Standardization of Common Lisp.
  1523.    ANSI            American National Standards Institute
  1524.    dpANS           draft proposed American National Standard (what an ANS
  1525.                    is called while it's in the public review stage of
  1526.                    standardization).
  1527.    CL              Common Lisp
  1528.    SC22/WG16       The full name is ISO/IEC JTC 1/SC 22/WG 16. It stands
  1529.                    for International Organization for Standardization/
  1530.                    International Electrotechnical Commission, Joint
  1531.                    Technical Committee 1 Subcommittee 22 (full name
  1532.                    "Information Technology -- Programming Languages
  1533.                    and their Environments"), Working Group 16.  This
  1534.                    long-winded name is the ISO working group working
  1535.                    on an international Lisp standard, (i.e., the ISO
  1536.                    analogue to X3J13). 
  1537.    CLtL1           First edition of Guy Steele's book, 
  1538.                    "Common Lisp the Language". 
  1539.    CLtL2           Second edition of Guy Steele's book,
  1540.                    "Common Lisp the Language". 
  1541.  
  1542. ----------------------------------------------------------------
  1543. Subject: [1-7] Lisp Job Postings
  1544.  
  1545. The LISP-JOBS mailing list exists to help programmers find Lisp
  1546. programming positions, and to help companies with Lisp programming
  1547. positions find capable Lisp programmers. (Lisp here means Lisp-like
  1548. languages, including Scheme.)
  1549.  
  1550. Material appropriate for the list includes Lisp job announcements and
  1551. should be sent to ai+lisp-jobs@cs.cmu.edu. Resumes should NOT be sent to
  1552. the list. 
  1553.  
  1554. [Note: The 'ai+' part of the mailing list name is used for directing
  1555. submissions to the appropriate mail-server. The list is NOT restricted
  1556. to AI-related Lisp jobs -- all Lisp job announcements are welcome.]
  1557.  
  1558. As a matter of policy, the contents of this mailing list is
  1559. considered confidential and will not be disclosed to anybody.
  1560.  
  1561. To subscribe, send a message to ai+query@cs.cmu.edu with
  1562.    subscribe lisp-jobs <First Name> <Last Name>, <Affiliation/Organization>
  1563. in the message body. 
  1564.  
  1565. (If your mailer objects to the "+", send subscription requests to
  1566. "ai+query"@cs.cmu.edu, job announcements to "ai+lisp-jobs"@cs.cmu.edu, etc.)  
  1567.  
  1568. For help on using the query server, send mail to ai+query@cs.cmu.edu with
  1569.    help
  1570. in the message body.
  1571.  
  1572. If you have any other questions, please send them to ai+@cs.cmu.edu
  1573.  
  1574. ----------------------------------------------------------------
  1575.  
  1576. ;;; *EOF*
  1577.  
  1578.